package cp3120.dao.remote;

import cp3120.dao.UserDAO;
import cp3120.model.Permission;
import cp3120.model.Role;
import generic.net.client.Client;
import cp3120.model.User;
import java.util.List;

/**
 *
 * @author Adam Scarr <scarr.adam@gmail.com>
 */
public class RemoteUserDAO implements UserDAO {
    private Client client;

    /**
     * Identifies this service
     */
    private static final String service = "RemoteUserService";

    /**
     * creates a RemoteUserDAO and sets the client
     * @param client the client this DAO is connected too
     */
    public RemoteUserDAO(Client client) {
        this.client = client;
    }

    /**
     * sends a request to the server to get a user
     * @param username the username of the user to be retreived
     * @return a user sent by the server
     */
    public User getUser(String username) {
        return (User)client.sendRequest(service, "getUser", username).getResponse().getPayload();
    }

    /**
     * sends a request to the server to get a list of all users
     * @return a list of users sent from the server
     */
    public List<User> getUsers() {
        return (List<User>)client.sendRequest(service, "getUsers").getResponse().getPayload();
    }

    /**
     * sends a request to the server to update a user
     * @param user the upadeted user
     * @return a booelan result from the server
     */
    public boolean updateUser(User user) {
        return (Boolean)client.sendRequest(service, "updateUser", user).getResponse().getPayload();
    }

    /**
     * sends a request to the server to add a user
     * @param user the user to be added
     * @return a booelan result from the server
     */
    public boolean addUser(User user) {
        return (Boolean)client.sendRequest(service, "addUser", user).getResponse().getPayload();
    }

    /**
     * sends a request to the server to delete a user
     * @param user the user to be deleted
     * @return a booelan result from the server
     */
    public boolean deleteUser(User user) {
        return (Boolean)client.sendRequest(service, "deleteUser", user).getResponse().getPayload();
    }

    /**
     * sends a request to the server for a lsit of all roles
     * @return a list of roles from the server
     */
    public List<Role> getRoles() {
        return (List<Role>)client.sendRequest(service, "getRoles").getResponse().getPayload();
    }

    /**
     * sends a request to the server to update a role
     * @param role the role to be updated
     * @return a booelan result from the server
     */
    public boolean updateRole(Role role) {
        return (Boolean)client.sendRequest(service, "updateRole", role).getResponse().getPayload();
    }

    /**
     * sends a request to the server to delete a role
     * @param role the roll to be deleted
     * @return a booelan result from the server
     */
    public boolean deleteRole(Role role) {
        return (Boolean)client.sendRequest(service, "deleteRole", role).getResponse().getPayload();
    }

    /**
     * sends a request to the server to add a role
     * @param role the new role to be added
     * @return a booelan result from the server
     */
    public boolean addRole(Role role) {
        return (Boolean)client.sendRequest(service, "addRole", role).getResponse().getPayload();
    }

    /**
     * sends a request to the server for a lsit of all permissions
     * @return a lsit of permissions sent from the server
     */
    public List<Permission> getPermissions() {
        return (List<Permission>)client.sendRequest(service, "getPermissions").getResponse().getPayload();
    }
}
